Skip to content

fix(server): stop completed delegate reruns and identical failing tool-call loops (CLO-1368) - #263

Merged
nullStack65 merged 3 commits into
release/native-0.1.10from
fix/clo-1368-m0-no-delegate-reruns
Dec 5, 2026
Merged

nullStack65 merged 3 commits into
release/native-0.1.10from
fix/clo-1368-m0-no-delegate-reruns

Conversation

@nullStack65

@nullStack65 nullStack65 commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Problem

On Dec 2 (ASUS incident, Bot Runtime Plan section 2.2 row 14 / CLO-1368 M0 Item 8), completed Gemini delegates on the Antigravity route were re-run automatically after completing:

  • Remote delegated threads launched with delegatedFrom have lineage.relationshipToParent === null, so AgentOutputGate, IdleCompaction, PullRequestWatchService, DelegationNudgeReactor, and RestartContinuation did not consistently recognize them as delegated threads, and Orchestrator.dispatchMessage did not suppress automatic server/system wakes on completed delegated threads.
  • Identical failing MCP tool calls (Neon retrying send_to_user over the 4,000-character cap 3 times; Carbon retrying a failing silent_ack) were executed repeatedly without a loop breaker.

Fix

  1. Completed-delegate no-rerun guards

    • Updated AgentOutputGate.ts (evaluateAgentOutputGate), IdleCompaction.ts, PullRequestWatchService.ts, DelegationNudgeReactor.ts, and RestartContinuation.ts to use isDelegatedAppThread(thread) (covering both local subagents and remote delegatedFrom threads, plus run.delegatedTaskId in AgentOutputGate).
    • Added shouldSuppressCompletedDelegateDispatch in CommandPolicy.ts and enforced it in Orchestrator.ts (dispatchMessage), including inspecting unmasked stored runs while turn-end checkpoint.capture masks a completed run as waiting. Suppresses output-gate bounces (isOutputGateBounceMessageId), system nudges/wakes, idle compaction, and restart/usage-limit continuations on completed delegates while allowing genuine user messages, parent MCP follow-ups, provider background-work completions (creationSource: "provider"), child task completions, and non-bounce monitor wakes.
    • Avoided redundant run.delegation-nudge-recorded writes in DelegationNudgeReactor.ts when uncounted tools leave stats unchanged.
  2. Identical failing tool-call loop guard

    • Added apps/server/src/mcp/McpToolLoopGuard.ts and wired withToolLoopGuard into apps/server/src/mcp/McpHttpServer.ts (toolkitRegistration and imageToolRegistration).
    • Tracks consecutive identical (scope, toolName, inputHash) failures using in-memory toolResultEpoch (zero extra SQLite reads per tool call), blocks a 3rd identical failing call before schema/handler execution with ToolCallLoopBlocked (code: "repeated_failure_blocked"), handles both Effect-channel errors (InvalidParams) and error CallToolResults (OrchestratorMcpFailure), resets on success / argument change / error fingerprint change / new turn epoch, and excludes linked peer-transport callers.
    • Calls mcpSessions.clearToolResults(input.threadId) in ProviderSessionManager.ts (busyTurn) before starting, resuming, or compacting a turn so non-ACP providers (Claude, Codex, Cursor, OpenCode, Pi) and ACP providers alike start every turn on a fresh epoch even when reusing providerSessionId.
    • Applies a 60-second Clock-based TTL (CLIENT_LOOP_GUARD_TTL_MS) to non-linked external MCP clients (client:<sessionId>) while preserving immediate reset on success.
  3. Regression tests

    • apps/server/src/orchestration-v2/CompletedDelegateNoRerun.test.ts: replays Dec 2 Antigravity Neon and Carbon remote delegates (zero restarts after completion, including during pending turn-end capture; new parent MCP and user follow-ups still run), plus idleCompactionWindow, restartContinuationBlocked, and shouldSuppressCompletedDelegateDispatch policy tests.
    • apps/server/src/mcp/McpToolLoopGuard.test.ts: unit tests + in-process McpServer replays of Dec 2 Neon (send_to_user > 4,000-char cap) and Carbon (silent_ack failing parent_not_active), non-ACP (codex) multi-turn reset via ProviderSessionManager without adapter clearToolResults, and non-linked external client TTL expiry + reset-on-success.
    • Extended AgentOutputGate.test.ts and PullRequestWatchService.test.ts for remote delegatedFrom / delegatedTaskId coverage.

Verification

  • Latest run after F1 fix (5 files, 174/174 passed):
    • apps/server/src/mcp/McpToolLoopGuard.test.ts (6/6)
    • apps/server/src/mcp/McpHttpServer.test.ts (44/44)
    • apps/server/src/orchestration-v2/CompletedDelegateNoRerun.test.ts (3/3)
    • apps/server/src/orchestration-v2/ProviderSessionManager.test.ts (81/81)
    • apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts (40/40)
  • Prior targeted server tests also verified: DelegatedCompletionDelivery.test.ts (79/79), RemoteDelegation.test.ts (73/73), AgentOutputGate.test.ts (10/10), PullRequestWatchService.test.ts (6/6), IdleCompaction.test.ts (14/14), DelegationNudge.integration.test.ts (3/3), RestartContinuation.test.ts, mcp/toolkits/core.test.ts.
  • vp fmt --write and vp lint --report-unused-disable-directives: pass (0 warnings, 0 errors).
  • apps/server typecheck (effect-tsgo tsrs --noEmit): pass (exit 0).
  • Note on knip: knip fails repo-wide on pre-existing release/native-0.1.10 findings (2 untouched .github/scripts/* files and pre-existing unused exports); 0 findings from this PR.

Head SHA: 1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0

Deploy: fleet

Model: gemini-4-neon
Task: fix
Agent: Builder
Harness: t3/antigravity
Model-family: Gemini (runtime model label)
Model-generation: 4 Neon (runtime model label)
Skills-SHA: f6ff9413445ca486f4e9b67f2209e6be8c2a51a1; skills/github-repository-ops/SKILL.md (sha256:e3778c3a953bfa9e7bf5c9b9609b6d6c947cffa03366b3bc0f75bbb722b76784)

…l-call loops (CLO-1368)

Implement Bot Runtime Plan M0 Item 8 (CLO-1368) so completed delegated
threads never restart automatically without genuinely new user/parent
input, and identical failing MCP tool calls are blocked before a third
unchanged retry.

- Completed-delegate no-rerun guards:
  - Treat both local subagents and remote `delegatedFrom` / `delegatedTaskId`
    runs as delegated threads in `AgentOutputGate`, `IdleCompaction`,
    `PullRequestWatchService`, `DelegationNudgeReactor`, and
    `RestartContinuation`.
  - Add `shouldSuppressCompletedDelegateDispatch` in `CommandPolicy` and
    enforce it in `Orchestrator.dispatchMessage` (including during the
    turn-end `checkpoint.capture` mask window) so server/system wakes cannot
    re-trigger a completed delegate while genuine user/parent/child-work
    messages still run.
  - Skip redundant `run.delegation-nudge-recorded` writes when uncounted
    tools leave delegation-nudge stats unchanged.
- Identical failing tool-call loop guard:
  - Add `McpToolLoopGuard` and wire `withToolLoopGuard` into
    `McpHttpServer` (`toolkitRegistration` and `imageToolRegistration`).
  - Block a 3rd identical failing call before schema/handler execution with
    `ToolCallLoopBlocked` (`code: "repeated_failure_blocked"`), resetting on
    success, argument changes, error fingerprint changes, or a new run/epoch,
    while excluding linked peer-transport calls.
- Regression tests:
  - Replay the Dec 2 Antigravity Neon (`send_to_user` > 4,000-char cap) and
    Carbon (`silent_ack` failing + post-completion wakes) cases across
    `CompletedDelegateNoRerun.test.ts`, `McpToolLoopGuard.test.ts`,
    `AgentOutputGate.test.ts`, and `PullRequestWatchService.test.ts`.

Model: gemini-4-neon
Task: fix
Agent: Builder
Harness: t3/antigravity
Model-family: Gemini (runtime model label)
Model-generation: 4 Neon (runtime model label)
Skills-SHA: f6ff9413445ca486f4e9b67f2209e6be8c2a51a1; skills/github-repository-ops/SKILL.md (sha256:e3778c3a953bfa9e7bf5c9b9609b6d6c947cffa03366b3bc0f75bbb722b76784)
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…/non-bounce wakes on subagents

- Scope `McpToolLoopGuard` with in-memory `toolResultEpoch` instead of
  calling `getThreadShell` on every MCP tool invocation (fixes extra
  `orchestration_v2_projection_messages` read in `RemoteDelegation.test.ts`).
- Narrow `shouldSuppressCompletedDelegateDispatch` to suppress output-gate
  bounces (`isOutputGateBounceMessageId`), system wakes, idle compaction,
  and restart/usage-limit continuations while allowing `creationSource:
  "provider"` background-work completions and non-bounce monitor wakes
  (fixes `DelegatedCompletionDelivery.test.ts`).

Model: gemini-4-neon
Task: fix
Agent: Builder
Harness: t3/antigravity
Model-family: Gemini (runtime model label)
Model-generation: 4 Neon (runtime model label)
Skills-SHA: f6ff9413445ca486f4e9b67f2209e6be8c2a51a1; skills/github-repository-ops/SKILL.md (sha256:e3778c3a953bfa9e7bf5c9b9609b6d6c947cffa03366b3bc0f75bbb722b76784)
@nullStack65

Copy link
Copy Markdown
Owner Author
{
  "reviewed_base": "6382e077dede0c225c1cac0c7b2c4ec14e0a04a8",
  "reviewed_head": "241d89e88028405aeb00bfa56d89d9e798823848",
  "reviewer": "gemini-4-neon (t3/antigravity)",
  "author_session": "mcp:launch:fe6ee53d8a8ec336906b18d6dfb5de759c4cee8d6277df30ac875cd850d38a70",
  "reviewer_session": "t3:antigravity:699dea85-7323-411e-a2a0-136c263d338c",
  "round_id": "t3:antigravity:699dea85-7323-411e-a2a0-136c263d338c",
  "fresh_context": true,
  "review_kind": "full",
  "intent": [
    "CLO-1368 M0-8: stop automatic reruns of completed delegates without new input and prevent identical failing tool-call retry loops"
  ],
  "prior_findings": [],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "outcome": "open",
      "file": "apps/server/src/mcp/McpHttpServer.ts",
      "line": 1335,
      "summary": "withToolLoopGuard scopes thread streaks by McpProviderSessions.toolResultEpoch, which is only incremented by provider-acp (packages/provider-acp/src/server/adapter.ts:8937). Non-ACP providers (Claude, Codex, Cursor, OpenCode, Pi) reuse providerSessionId across turns (ProviderSessionManager.ts:660-674) without calling clearToolResults, and non-linked external MCP clients (client:<sessionId>) have no epoch or TTL. Because guard.check(key) short-circuits before options.handle(payload), two identical transient failures permanently block that tool+args across all subsequent turns until 512-key LRU eviction or server restart.",
      "check": "git grep -n clearToolResults 241d89e88028405aeb00bfa56d89d9e798823848 shows only packages/provider-acp/src/server/adapter.ts:8937 calls clearToolResults in production; ProviderSessionManager.ts:660-674 reuses existing.providerSessionId across turns."
    }
  ]
}

Independent Clean-Room Full Review (#2 of 2)

Completed-delegate no-rerun guards:

  • AgentOutputGate.ts, DelegationNudgeReactor.ts, IdleCompaction.ts, RestartContinuation.ts, and PullRequestWatchService.ts consistently use isDelegatedAppThread(thread) (covering both local subagents and remote delegatedFrom threads).
  • CommandPolicy.ts (shouldSuppressCompletedDelegateDispatch) and Orchestrator.ts (dispatchMessage, including unmasked stored runs during turn-end checkpoint.capture) suppress automatic server/system restarts while allowing genuine user messages, parent MCP follow-ups, provider background-work completions, and grandchild completions.
  • CompletedDelegateNoRerun.test.ts replays the Dec 2 Antigravity Neon and Carbon remote delegates with zero restarts after completion.

Identical failing tool-call loop guard:

  • F1 (important) — apps/server/src/mcp/McpHttpServer.ts:1335 (McpToolLoopGuard.ts:71): withToolLoopGuard relies on McpProviderSessions.toolResultEpoch(thread.threadId) to reset per-turn retry budgets, but clearToolResults is only called by packages/provider-acp/src/server/adapter.ts:8937. On all non-ACP providers (Claude, Codex, Cursor, OpenCode, Pi), ProviderSessionManager.ts:660-674 reuses providerSessionId across turns without bumping toolResultEpoch (and client:<sessionId> external clients have no epoch or TTL). Since guard.check(key) returns ToolCallLoopBlocked before options.handle(payload) executes, two identical transient failures (e.g. preview_open, pull_request_merge, ci_logs, silent_ack) permanently wedge that tool+arguments on all future turns of the thread/session until 512-key LRU eviction or server restart. Fix by advancing the turn epoch at every turn start across all providers (e.g. in RunExecutionService / ProviderSessionManager) or scoping by active run/turn ID, and bounding/expiring client:<sessionId> entries.

@nullStack65

Copy link
Copy Markdown
Owner Author
{
  "reviewed_base": "6382e077dede0c225c1cac0c7b2c4ec14e0a04a8",
  "reviewed_head": "241d89e88028405aeb00bfa56d89d9e798823848",
  "reviewer": "claude-sonnet-5-5 (t3/antigravity)",
  "author_session": "mcp:launch:fe6ee53d8a8ec336906b18d6dfb5de759c4cee8d6277df30ac875cd850d38a70",
  "reviewer_session": "0e88f4d6-a1d3-4532-a50f-a1cc25763a7f",
  "fresh_context": true,
  "review_kind": "full",
  "round_id": "0e88f4d6-a1d3-4532-a50f-a1cc25763a7f",
  "intent": [
    "CLO-1368 M0-8: stop automatic reruns of completed delegates without new input and prevent identical failing tool-call retry loops",
    "bot-runtime-plan-20261201 M0 item 8 and exact check 8: replaying the two Antigravity delegates from December 2 yields zero restarts after completion and no third identical failing call"
  ],
  "prior_findings": [],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "summary": "The loop guard blocks an identical failing call permanently for every provider except ACP. The scope key is thread:providerSession:toolResultEpoch, and the epoch only advances when mcpSessions.clearToolResults runs. Only packages/provider-acp/src/server/adapter.ts:8937 calls it (turn terminal), so Claude, Codex, OpenCode, Grok, Pi and similar sessions keep epoch 0 for the whole provider session. A blocked call never reaches the handler, so the streak is never cleared by a success. Once a (tool, args) pair has failed twice with the same error, the same call stays refused after the world changed, for example a pull_request_merge that failed on pending checks, or a transient environment-unreachable error, until the session is replaced. Neither a new run nor a new user message nor elapsed time resets it. This breaks legitimate polling and retry on the main providers, which is a larger blast radius than the Antigravity loop it fixes. The replay test hides this because it calls clearToolResults by hand and uses an ACP-style flow. The test layer still stubs getThreadShell.activeRunId, which suggests an earlier run-scoped design that did not have this gap. Fix: scope or reset the streak per run or turn for all providers (active run id from the thread shell, or bump the epoch in every adapter's turn terminal) and/or expire streaks after a short TTL; add a test with no clearToolResults call proving a new run unblocks.",
      "outcome": "open",
      "file": "apps/server/src/mcp/McpToolLoopGuard.ts",
      "line": 70,
      "check": "git grep clearToolResults at 241d89e8: only provider-acp adapter.ts:8937 (plus tests); ClaudeAdapterV2.ts, CodexAdapterV2.ts and ProviderSessionManager.ts have no clearToolResults or epoch handling. Read McpToolLoopGuard.ts check/record (blocked calls return before record) and McpHttpServer.withToolLoopGuard. Local vitest was not run: a worktree install did not complete on the loaded host."
    },
    {
      "id": "F2",
      "severity": "nit",
      "summary": "shouldSuppressCompletedDelegateDispatch is a denylist: it suppresses only restart/usage-limit/idle-compaction/output-gate-bounce ids and notification.source.kind === 'system'. Other server-originated wakes still restart a completed delegate, for example a ModelAlertReactor event-subscription wake (creationSource server, monitor/updated notification) or an alert delivery with no notification. The new test pins the monitor/updated case as allowed. If that is intended, say so in the doc comment; otherwise default-deny server-origin wakes without a parent, user or provider source.",
      "outcome": "open",
      "file": "apps/server/src/orchestration-v2/CommandPolicy.ts",
      "line": 122,
      "check": "Read ModelAlertReactor.ts deliverAlertToWatcher and the subscription wake at head: both dispatch createdBy agent, creationSource server, queue_after_active, with no output-gate or system marker."
    },
    {
      "id": "F3",
      "severity": "nit",
      "summary": "Behavior changes outside M0 item 8 and outside the brief's scope (orchestration-v2 plus tests): PullRequestWatchService now refuses watch for remote-delegated threads; DelegationNudgeReactor skips every delegated thread, including active runs, and gains an unrelated record-skip optimization (previousStats). The plan lists none of these. Split or call them out in the PR body so the CTO can accept them explicitly.",
      "outcome": "open",
      "file": "apps/server/src/pullRequest/PullRequestWatchService.ts",
      "line": 121,
      "check": "Compared gh pr diff 263 against M0 item 8 text and exact check 8 (recovered from closura-agent-config commit 215328960, since docs/architecture/bot-runtime-plan-20261201.md is no longer on the checked-out branch)."
    },
    {
      "id": "F4",
      "severity": "nit",
      "summary": "Model-facing text changed without an eval: the output-gate bounce prompt is edited (em dash to colon, cosmetic) and a new ToolCallLoopBlocked message is introduced. AGENTS.md and evals/README.md require reading and running the evals before changing such text, and adding a case for a model-behavior bug (the Dec 2 loops). Revert the cosmetic prompt edit, or add an evals/mcp-tool-use case where a blocked-call result makes the model change arguments instead of retrying.",
      "outcome": "open",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 21,
      "check": "git grep for the prompt string finds only AgentOutputGate.ts; evals/ has no case touched by the diff."
    }
  ]
}

Full review #1 of 2 (Tier 3, Claude family). The restart half of M0 item 8 is sound: AgentOutputGate now exempts remote delegates, the dispatch guard suppresses automatic restarts of completed delegates, and idle compaction and restart continuation skip them. Real new input (user, parent MCP send, provider, grandchild completion) is still allowed. The loop-guard half has the F1 gap, so exact check 8 is not fully met for non-ACP providers. The head's merge-base with the stated base is e339723, so the branch is not rebased on the reviewed base.

…xternal client streaks (F1)

Address clean-room review F1 on PR #263:
- Call `mcpSessions.clearToolResults(input.threadId)` in
  `ProviderSessionManager` (`busyTurn`) before starting, resuming, or
  compacting a turn so every provider (non-ACP providers like Claude,
  Codex, Cursor, OpenCode, and Pi as well as ACP) starts each turn on a
  fresh `toolResultEpoch` with zero extra SQLite reads per MCP tool call.
- Add a 60-second `Clock`-based TTL (`CLIENT_LOOP_GUARD_TTL_MS`) for
  non-linked external MCP clients (`client:<sessionId>`) in
  `McpToolLoopGuard` while keeping immediate reset on success.
- Add regression tests in `McpToolLoopGuard.test.ts` verifying:
  - A non-ACP (`codex`) provider reusing one `providerSessionId` across
    turns without adapter `clearToolResults` blocks the 3rd identical
    failing call in Turn 1 and resets the budget on Turn 2.
  - Non-linked external client streaks expire after `CLIENT_LOOP_GUARD_TTL_MS`
    and reset immediately on success.

Model: gemini-4-neon
Task: fix
Agent: Builder
Harness: t3/antigravity
Model-family: Gemini (runtime model label)
Model-generation: 4 Neon (runtime model label)
Skills-SHA: f6ff9413445ca486f4e9b67f2209e6be8c2a51a1; skills/github-repository-ops/SKILL.md (sha256:e3778c3a953bfa9e7bf5c9b9609b6d6c947cffa03366b3bc0f75bbb722b76784)
@nullStack65

Copy link
Copy Markdown
Owner Author
{
  "reviewed_base": "6382e077dede0c225c1cac0c7b2c4ec14e0a04a8",
  "reviewed_head": "1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0",
  "reviewer": "claude-sonnet-5-5 (t3/antigravity)",
  "author_session": "mcp:launch:fe6ee53d8a8ec336906b18d6dfb5de759c4cee8d6277df30ac875cd850d38a70",
  "reviewer_session": "364dda0b-a43d-4573-92ae-3fe0f9e63337",
  "fresh_context": true,
  "review_kind": "focused_recheck",
  "round_id": "0e88f4d6-a1d3-4532-a50f-a1cc25763a7f",
  "intent": [
    "CLO-1368 M0-8: stop automatic reruns of completed delegates without new input and prevent identical failing tool-call retry loops"
  ],
  "prior_findings": [
    "F1"
  ],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "summary": "The loop guard blocks an identical failing call permanently for every provider except ACP. The scope key is thread:providerSession:toolResultEpoch, and the epoch only advances when mcpSessions.clearToolResults runs. Only packages/provider-acp/src/server/adapter.ts:8937 calls it (turn terminal), so Claude, Codex, OpenCode, Grok, Pi and similar sessions keep epoch 0 for the whole provider session. A blocked call never reaches the handler, so the streak is never cleared by a success. Once a (tool, args) pair has failed twice with the same error, the same call stays refused after the world changed, for example a pull_request_merge that failed on pending checks, or a transient environment-unreachable error, until the session is replaced. Neither a new run nor a new user message nor elapsed time resets it. This breaks legitimate polling and retry on the main providers, which is a larger blast radius than the Antigravity loop it fixes. The replay test hides this because it calls clearToolResults by hand and uses an ACP-style flow. The test layer still stubs getThreadShell.activeRunId, which suggests an earlier run-scoped design that did not have this gap. Fix: scope or reset the streak per run or turn for all providers (active run id from the thread shell, or bump the epoch in every adapter's turn terminal) and/or expire streaks after a short TTL; add a test with no clearToolResults call proving a new run unblocks.",
      "outcome": "confirmed",
      "file": "apps/server/src/mcp/McpToolLoopGuard.ts",
      "line": 70,
      "check": "Read repair delta 241d89e8..1c6d4ffc: ProviderSessionManager.busyTurn (shared by startTurn, resumeTurn, compactThread for every adapter) now calls mcpSessions.clearToolResults(threadId) after markBusy and before the turn runs; clearThreadToolResults bumps the per-thread epoch that loopGuardScopeKey embeds, so every provider turn gets a fresh streak scope. Non-linked client:<sessionId> scopes now carry a 60s Clock TTL (loopGuardTtlMs, applied in check and record; blocked calls do not refresh it). Linked peer transport stays excluded. Tests in McpToolLoopGuard.test.ts: codex adapter that never calls clearToolResults and reuses one providerSessionId over a real ProviderSessionManager/ProviderReplayHarness; turn 1 blocks the 3rd identical failure (handler calls 2), turn 2 epoch is higher and the same call runs the handler (calls 3); TestClock test for the client TTL (still blocked at 59.999s, recovers at 60s, success resets). Local vitest not run: no node_modules in this worktree and host load average ~40-60; CI jobs on the head were queued at review time.",
      "rechecked_head": "1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0"
    },
    {
      "id": "F2",
      "severity": "nit",
      "summary": "shouldSuppressCompletedDelegateDispatch is a denylist: it suppresses only restart/usage-limit/idle-compaction/output-gate-bounce ids and notification.source.kind === 'system'. Other server-originated wakes still restart a completed delegate, for example a ModelAlertReactor event-subscription wake (creationSource server, monitor/updated notification) or an alert delivery with no notification. The new test pins the monitor/updated case as allowed. If that is intended, say so in the doc comment; otherwise default-deny server-origin wakes without a parent, user or provider source.",
      "outcome": "open",
      "file": "apps/server/src/orchestration-v2/CommandPolicy.ts",
      "line": 122,
      "check": "Read ModelAlertReactor.ts deliverAlertToWatcher and the subscription wake at head: both dispatch createdBy agent, creationSource server, queue_after_active, with no output-gate or system marker."
    },
    {
      "id": "F3",
      "severity": "nit",
      "summary": "Behavior changes outside M0 item 8 and outside the brief's scope (orchestration-v2 plus tests): PullRequestWatchService now refuses watch for remote-delegated threads; DelegationNudgeReactor skips every delegated thread, including active runs, and gains an unrelated record-skip optimization (previousStats). The plan lists none of these. Split or call them out in the PR body so the CTO can accept them explicitly.",
      "outcome": "open",
      "file": "apps/server/src/pullRequest/PullRequestWatchService.ts",
      "line": 121,
      "check": "Compared gh pr diff 263 against M0 item 8 text and exact check 8 (recovered from closura-agent-config commit 215328960, since docs/architecture/bot-runtime-plan-20261201.md is no longer on the checked-out branch)."
    },
    {
      "id": "F4",
      "severity": "nit",
      "summary": "Model-facing text changed without an eval: the output-gate bounce prompt is edited (em dash to colon, cosmetic) and a new ToolCallLoopBlocked message is introduced. AGENTS.md and evals/README.md require reading and running the evals before changing such text, and adding a case for a model-behavior bug (the Dec 2 loops). Revert the cosmetic prompt edit, or add an evals/mcp-tool-use case where a blocked-call result makes the model change arguments instead of retrying.",
      "outcome": "open",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 21,
      "check": "git grep for the prompt string finds only AgentOutputGate.ts; evals/ has no case touched by the diff."
    }
  ]
}

Focused re-check (Claude family) of repair delta 241d89e8..1c6d4ffc for F1. F1 is fixed: every provider turn (start, resume, compact) now bumps the tool-result epoch in ProviderSessionManager.busyTurn, so the loop-guard scope resets per turn for non-ACP providers, and external non-linked MCP clients expire streaks after 60s. A new test drives a codex-style adapter that never calls clearToolResults through the real session manager and shows turn 2 unblocked; a TestClock test covers the TTL. F2, F3 and F4 are unchanged nits and remain open. Tests were not run locally (no install, host overloaded); CI on the head was still queued.

@nullStack65

Copy link
Copy Markdown
Owner Author

Note

🤖 grok-4.7 responding on behalf of nullStack65

{
  "reviewed_base": "6382e077dede0c225c1cac0c7b2c4ec14e0a04a8",
  "reviewed_head": "1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0",
  "reviewer": "grok-4.7 (t3/grok-direct)",
  "author_session": "mcp:launch:fe6ee53d8a8ec336906b18d6dfb5de759c4cee8d6277df30ac875cd850d38a70",
  "reviewer_session": "t3:grok-direct:01a24006-a72a-7382-abb8-b284bffd6347",
  "fresh_context": true,
  "review_kind": "focused_recheck",
  "round_id": "t3:antigravity:699dea85-7323-411e-a2a0-136c263d338c",
  "intent": [
    "CLO-1368 M0-8: stop automatic reruns of completed delegates without new input and prevent identical failing tool-call retry loops"
  ],
  "prior_findings": [
    "F1"
  ],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "outcome": "confirmed",
      "file": "apps/server/src/mcp/McpHttpServer.ts",
      "line": 1335,
      "summary": "withToolLoopGuard scopes thread streaks by McpProviderSessions.toolResultEpoch, which is only incremented by provider-acp (packages/provider-acp/src/server/adapter.ts:8937). Non-ACP providers (Claude, Codex, Cursor, OpenCode, Pi) reuse providerSessionId across turns (ProviderSessionManager.ts:660-674) without calling clearToolResults, and non-linked external MCP clients (client:<sessionId>) have no epoch or TTL. Because guard.check(key) short-circuits before options.handle(payload), two identical transient failures permanently block that tool+args across all subsequent turns until 512-key LRU eviction or server restart.",
      "check": "Repair delta 241d89e88028405aeb00bfa56d89d9e798823848..1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0: ProviderSessionManager.busyTurn (startTurn, resumeTurn, compactThread) calls mcpSessions.clearToolResults after markBusy and before the turn (ProviderSessionManager.ts:2637). clearThreadToolResults increments the per-thread epoch embedded by loopGuardScopeKey (McpToolLoopGuard.ts:74, thread:threadId:providerSessionId:epoch), so a reused providerSessionId still gets a new scope. Non-linked client scopes get loopGuardTtlMs of 60000; check and record treat an expired streak as absent, and a blocked call does not refresh updatedAtMs. Linked peers stay excluded. Ran `pnpm exec vp test run src/mcp/McpToolLoopGuard.test.ts` at 1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0: 6 passed (1 file), including the codex it.live case (adapter never calls clearToolResults, same providerSessionId, turn 1 blocks the 3rd identical failure after 2 handler calls, turn 2 epoch is higher and the same call runs the handler) and the TestClock non-linked client TTL case.",
      "rechecked_head": "1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0"
    }
  ]
}

F1 is fixed on 1c6d4ffc460042057fa6dd2cf5edb88f0576e0d0. ProviderSessionManager.busyTurn calls clearToolResults before startTurn, resumeTurn, and compactThread, and that bump is the epoch inside the loop-guard scope key, so a reused providerSessionId on Claude, Codex, Cursor, OpenCode, and Pi no longer keeps a blocked tool+args pair forever. Non-linked external clients expire a streak after 60 seconds. pnpm exec vp test run src/mcp/McpToolLoopGuard.test.ts at this head: 6 passed.

@nullStack65 nullStack65 added the size-approved Founder accepted this PR over the 1500-line size gate label Dec 5, 2026
@nullStack65
nullStack65 merged commit 8630677 into release/native-0.1.10 Dec 5, 2026
11 of 22 checks passed
@nullStack65
nullStack65 deleted the fix/clo-1368-m0-no-delegate-reruns branch December 5, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-approved Founder accepted this PR over the 1500-line size gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant